<template>
	<div class="index">
	</div>
</template>

<script>
export default {
	created() {
		this.getNav();
	},
	methods: {
		getNav() {
			this.$store.dispatch('user/getInfo');
			this.Sevice({
				url: 'sys/menu/nav',
				method: 'get',
			}).then(res => {
				if (res && res.code == 200) {
					console.log(res.menuList)
					sessionStorage.setItem('menuArr', JSON.stringify(res.menuList));
					if (res.menuList.length > 0) {
						let m = this.redirectPage2(1, JSON.parse(JSON.stringify(res.menuList)), [])
						console.log(m)
						this.$router.push({
							path: this.$route.query.redirect || '/'
						})
					} else {
						sessionStorage.setItem("menuArr", null);
						sessionStorage.setItem("Token", "");
						this.$router.push("/login");
						this.$message({
							type: "error",
							message: "暂无权限，请联系管理员！",
						});
					}
				}
			}).catch(err => {
				console.log(err);
			})
		},
		redirectPage2(searchItem, allRoutes, resultArr = []) {
			for (var i = 0; i < allRoutes.length; i++) {
				if (allRoutes[i].list && allRoutes[i].list.length) {
					this.redirectPage2(searchItem, allRoutes[i].list, resultArr);
				} else {
					if (allRoutes[i].type == searchItem) {
						resultArr.push(allRoutes[i])
					}
				}
			}
			return resultArr
		},
	}
}
</script>

<style scoped></style>
